package com.tjetc.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tjetc.vo.Result;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import com.tjetc.mapper.SpecializedGroupMapper;
import com.tjetc.domain.SpecializedGroup;
import com.tjetc.service.SpecializedGroupService;

import java.util.List;

@Service
public class SpecializedGroupServiceImpl implements SpecializedGroupService{

    @Resource
    private SpecializedGroupMapper specializedGroupMapper;

    @Override
    public int deleteByPrimaryKey(Integer id) {
        return specializedGroupMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(SpecializedGroup record) {
        return specializedGroupMapper.insert(record);
    }

    @Override
    public int insertSelective(SpecializedGroup record) {
        return specializedGroupMapper.insertSelective(record);
    }

    @Override
    public SpecializedGroup selectByPrimaryKey(Integer id) {
        return specializedGroupMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(SpecializedGroup record) {
        return specializedGroupMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(SpecializedGroup record) {
        return specializedGroupMapper.updateByPrimaryKey(record);
    }

    @Override
    public Result selectAll() {
        List<SpecializedGroup> list = specializedGroupMapper.selectAll();
        return Result.ok(list);
    }

    @Override
    public List<SpecializedGroup> selectByName(String name) {

        return specializedGroupMapper.findByName(name);
    }

    @Override
    public PageInfo<SpecializedGroup> getByNameandPage(String name, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<SpecializedGroup> list = specializedGroupMapper.getByNameandPage(name);
        return new PageInfo<>( list);
    }

    @Override
    public Result save(SpecializedGroup specializedGroup) {
        int i=0;
        if (specializedGroup.getId() == null){
           i= specializedGroupMapper.insertSelective(specializedGroup);
        }else {
           i= specializedGroupMapper.updateByPrimaryKeySelective(specializedGroup);
        }
        return i==0?Result.fail("添加失败"):Result.ok();
    }

}
